package com.mydemo.game.resaultStage;

import com.mydemo.entity.Car;
import com.mydemo.entity.Save;

import java.util.Scanner;

public class CarAddDays {
    static Scanner scanner = new Scanner(System.in);
    public static final Save carAddDays(Save save) {
        boolean flag = true;
        while (flag) {
            for (Car car :
                    save.getCarList()) {
                System.out.println("Id:" + car.getId() + " 车辆" + car.getCarBrand() + car.getCarModel() + car.getCarModelDetail() + " 剩余时间：" + car.getDays());
            }
            System.out.println("请选择需要续费的车辆,输入0退出");
            int choose = scanner.nextInt();
            if (choose == 0) {
                flag = false;
            } else {
                for (Car chosenCar :
                        save.getCarList()) {
                    if (chosenCar.getId() == choose) {
                        System.out.println("该车辆剩余的天数：" + chosenCar.getDays());
                        System.out.println("请输入需要续费的天数，输入0退出");
                        int addDays = scanner.nextInt();
                        if (addDays == 0) {
                            System.out.println("退出");
                            flag = false;
                        } else {
                            int money = addDays * chosenCar.getRentPrise();
                            if (money > save.getMoney()) {
                                System.out.println("金额不足，以自动退出");
                                flag = false;
                            } else {
                                save.setMoney(save.getMoney() - money);
                                chosenCar.setDays(chosenCar.getDays() + addDays);
                            }
                        }
                    }
                }
            }
        }

        return save;
    }
}
